using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Widgetsphere.Core.Logging
{
	public partial class DefaultLogConfiguration : ILogConfiguration
	{
		private const string DefaultFileName = "Default.Widgetsphere.log";
		private const string DefaultFileLength = "5242880";
		private readonly List<TraceListener> _listeners = null;
		#region ILogConfiguration Members
		public bool AutoFlush
		{
			get
			{
				return true;
			}
		}

		public TraceLevel GetTraceLevel(string switchName)
		{
			return TraceLevel.Verbose;
		}

		public int IndentSize
		{
			get
			{
				return 0;
			}
		}

		public event EventHandler LogConfigurationChanged;

		public List<TraceListener> TraceListeners
		{
			get
			{

				if (_listeners == null)
				{
					//_listeners = new List<TraceListener>();
					_listeners.Add(CreateDefaultListener());
				}
				return _listeners;
			}
		}

		private TraceListener CreateDefaultListener()
		{
			var inputData = "C:\\";
			inputData = inputData + DefaultFileName +"?" + DefaultFileLength;
			TraceListener mpftl = new MultiProcessFileTraceListener(inputData);
			return mpftl;
		}

		#endregion

		#region Dispose Stuff

		public void Dispose()
		{
			Dispose(true);
		}

		protected void Dispose(bool disposing) { }

		~DefaultLogConfiguration()
		{
			Dispose(false);
		}

		#endregion

	}
}
